<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="黑名单编号" prop="blacklistId">-->
<!--        <el-input-->
<!--          v-model="queryParams.blacklistId"-->
<!--          placeholder="请输入黑名单编号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="门卡编号" prop="accessCardId">
        <el-input
          v-model="queryParams.accessCardId"
          placeholder="请输入门禁卡编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡主姓名" prop="holderName">
        <el-input
          v-model="queryParams.holderName"
          placeholder="请输入持卡人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入持卡者手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在小区" prop="vllageName">
        <el-input
          v-model="queryParams.vllageName"
          placeholder="请输入持卡人所在小区名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单元号" prop="unitNum">
        <el-input
          v-model="queryParams.unitNum"
          placeholder="请输入单元号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="栋号" prop="buildingNum">
        <el-input
          v-model="queryParams.buildingNum"
          placeholder="请输入栋号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="层号" prop="floorNum">
        <el-input
          v-model="queryParams.floorNum"
          placeholder="请输入层号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间号" prop="roomNum">
        <el-input
          v-model="queryParams.roomNum"
          placeholder="请输入房间号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="加入黑名单的理由" prop="remarks">-->
<!--        <el-input-->
<!--          v-model="queryParams.remarks"-->
<!--          placeholder="请输入加入黑名单的理由"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:blacklist_records:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:blacklist_records:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:blacklist_records:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:blacklist_records:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="blacklist_recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="黑名单编号" align="center" prop="blacklistId" />-->
      <el-table-column label="门卡编号" width="150" align="center" prop="accessCardId" >
        <template slot-scope="scope">
          <span>{{getShortId(scope.row.accessCardId)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="卡主姓名" align="center" prop="holderName" />
      <el-table-column label="手机号码" width="120" align="center" prop="phone" />
      <el-table-column label="所在小区" align="center" prop="vllageName" />
      <el-table-column label="单元号" align="center" prop="unitNum" />
      <el-table-column label="栋号" align="center" prop="buildingNum" />
      <el-table-column label="层号" align="center" prop="floorNum" />
      <el-table-column label="房间号" align="center" prop="roomNum" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="拉黑原因" align="center" prop="remarks" />
      <el-table-column label="操作"  width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:blacklist_records:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:blacklist_records:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改黑名单记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="黑名单编号" prop="blacklistId">
          <el-input v-model="form.blacklistId" placeholder="请输入黑名单编号" />
        </el-form-item>
        <el-form-item label="门禁卡编号" prop="accessCardId">
          <el-input v-model="form.accessCardId" placeholder="请输入门禁卡编号" />
        </el-form-item>
        <el-form-item label="持卡人姓名" prop="holderName">
          <el-input v-model="form.holderName" placeholder="请输入持卡人姓名" />
        </el-form-item>
        <el-form-item label="持卡者手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入持卡者手机号码" />
        </el-form-item>
        <el-form-item label="持卡人所在小区名称" prop="vllageName">
          <el-input v-model="form.vllageName" placeholder="请输入持卡人所在小区名称" />
        </el-form-item>
        <el-form-item label="单元号" prop="unitNum">
          <el-input v-model="form.unitNum" placeholder="请输入单元号" />
        </el-form-item>
        <el-form-item label="栋号" prop="buildingNum">
          <el-input v-model="form.buildingNum" placeholder="请输入栋号" />
        </el-form-item>
        <el-form-item label="层号" prop="floorNum">
          <el-input v-model="form.floorNum" placeholder="请输入层号" />
        </el-form-item>
        <el-form-item label="房间号" prop="roomNum">
          <el-input v-model="form.roomNum" placeholder="请输入房间号" />
        </el-form-item>
        <el-form-item label="加入黑名单的理由" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入加入黑名单的理由" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBlacklist_records, getBlacklist_records, delBlacklist_records, addBlacklist_records, updateBlacklist_records, exportBlacklist_records } from "@/api/system/blacklist_records";

export default {
  name: "Blacklist_records",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 黑名单记录表格数据
      blacklist_recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        blacklistId: null,
        accessCardId: null,
        holderName: null,
        phone: null,
        vllageName: null,
        unitNum: null,
        buildingNum: null,
        floorNum: null,
        roomNum: null,
        createTime: null,
        remarks: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //截取UUID的末尾，并且转换为大写，用作短ID
    getShortId(uuid){
      let split = uuid.split("-");
      let len = split.length;
      return split[len-1].toUpperCase();
    },
    /** 查询黑名单记录列表 */
    getList() {
      this.loading = true;
      listBlacklist_records(this.queryParams).then(response => {
        this.blacklist_recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        blacklistId: null,
        accessCardId: null,
        holderName: null,
        phone: null,
        vllageName: null,
        unitNum: null,
        buildingNum: null,
        floorNum: null,
        roomNum: null,
        createTime: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.blacklistId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加黑名单记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const blacklistId = row.blacklistId || this.ids
      getBlacklist_records(blacklistId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改黑名单记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.blacklistId != null) {
            updateBlacklist_records(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBlacklist_records(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const blacklistIds = row.blacklistId || this.ids;
      this.$confirm('是否确认删除黑名单记录编号为"' + blacklistIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBlacklist_records(blacklistIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有黑名单记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportBlacklist_records(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
